package keke.ai.code.mother.handle.security;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import keke.ai.code.mother.common.BaseResponse;
import keke.ai.code.mother.common.ResultUtils;
import keke.ai.code.mother.exception.ErrorCode;
import keke.ai.code.mother.util.WriteJson;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import java.io.IOException;

/**
 * 未登录处理
 */
public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
        BaseResponse<?> error = ResultUtils.error(ErrorCode.NOT_LOGIN_ERROR);
        WriteJson.writeJson(request,response, error);
    }
}
